from django.shortcuts import render, HttpResponse
from video_reptile import controller
import json

# Create your views here.

def index(request):
    return render(request, 'index.html')


def download_video(request):
    url = request.POST['url']
    cookie = request.POST['cookie']
    try:
        result = controller.get_video(url, cookie)
        print(result)
    except Exception as err:
        result = {
            'code' : 'FAIL',
            'message' : err
        }
        print(result)
    else:
        result['code'] = 'SUCCESS'

    print(result)
    return HttpResponse(json.dumps(result))